import axios from 'axios'
import Qs from 'axios'
import { cardUrl,orderUrl,addressUrl } from '../../baseUrl/index'
let state={}

let mutations={}

let actions={
    // 修改默认地址
    putAddress(context,id){
        return new Promise(function(resolve,reject){
            axios({
                url:addressUrl+'/'+id,
                method:'put',
                data:{
                    isdefault:0
                }
            })
            .then(()=>{
                resolve()
            })
        })
    },
    // 提交地址
    postAddress(context,obj){
        return new Promise(function(resolve,reject){
            axios({
                url:addressUrl,
                method:'post',
                data:obj
            })
            .then(data=>{
                resolve(data)
            })
        })
    },
    // 获取地址
    getAddress(context,uid){
        return new Promise(function(resolve,reject){
            axios({
                url:addressUrl,
                method:'get',
                params:{
                    transform:1,
                    filter:'uid,cs,'+uid
                }
            })
            .then(data=>{
                resolve(data.data.records)
            })
        })
    },
    submitOrder(context,obj){
        return new Promise(function(resolve,reject){
            axios({
                url:orderUrl,
                method:'post',
                data:obj
            })
            .then(data=>{
                resolve()
            })
        })
    },
    getShopCard(){
        return new Promise(function(resolve,reject){
            axios({
                url:cardUrl,
                method:'get',
                params:{},
            })
            .then(data=>{
                resolve(data.data.records)
            })
        })
    },
    updateShopsNum(comtext,obj){
        return new Promise(function(resolve,reject){
            axios({
                url:cardUrl+'/'+obj.id,
                method:'put',
                data:{
                    number:obj.num
                },
            })
            .then(data=>{
                resolve()
            })
        })
    },
    removeShopsCard(context,id){
        return new Promise(function(resolve,reject){
            axios({
                url:cardUrl+'/'+id,
                method:'delete'
            })
            .then(data=>{
                resolve()
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}